﻿package com.winmastergames.gameassets {
	import flash.display.*;
	import flash.geom.*;
	import com.winmastergames.lolgame.mapDefault;

	public class healthBar extends MovieClip {
		// TODO: Document This Class on Wiki.
		public var hHealth:Number = 100;
		public var hRem:Number = 100;
		public var hHPerc:Number;
		public var hAlive:Boolean = true;
		var hStageRef:MovieClip;

		public function healthBar(stageRef:MovieClip, attachTo:MovieClip, yOffset:Number, Health:Number, xLoc:Number = -1, yLoc:Number = -1){
			hHPerc = hHealth / hHealth;
			hHealth = Health;
			hRem = Health;
			hStageRef = stageRef;
			stageRef.addChild(this);
			if (xLoc == -1){
				x = 0;
			} else {
				x = xLoc;
			}
			if (yLoc == -1){
				y = yOffset;
			} else {
				y = yLoc;
			}
			inside.scaleX = hHPerc;
			height = 3.5;
			checkColours();
			inside.x -= inside.width;
		}

		public function setCoords(xLoc:Number, yLoc:Number){
			x = xLoc;
			y = yLoc;
		}

		public function setHealth(Value:Number) {
			inside.x -= hRem / 2.5;
			hRem = Value;
			inside.x += hRem / 2.5;
			hHPerc = Value / hHealth;
			checkColours();
		}

		public function killSelf(){
			if (hAlive == true){
				hAlive = false;
				hStageRef.removeChild(this);
			}
		}

		function checkColours(){
			var ColourTrans:ColorTransform = inside.transform.colorTransform;
			if (hHPerc >= 0.51){
				//Change MyMovieClip color to Green (00CC00)
				ColourTrans.color = 0x00CC00;
				inside.transform.colorTransform = ColourTrans;
			}
			if (hHPerc <= 0.50 && hHPerc > 0.30){
				//Change MyMovieClip color to Orange (FF9900)
				ColourTrans.color = 0xFF9900;
				inside.transform.colorTransform = ColourTrans;
			}
			if (hHPerc <= 0.30){
				//Change MyMovieClip color to Red (FF0000)
				ColourTrans.color = 0xFF0000;
				inside.transform.colorTransform = ColourTrans;
			}
		}
	}
}